﻿using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using Android.Content.PM;
using Java.Lang;

namespace GlobalTracker.Mobile
{
  [Activity(Label = "Global Tracker Location", MainLauncher = true, Theme = "@style/Theme.Splash", NoHistory = true, Icon = "@drawable/icon")]
  public class ActivitySplashScreen : Activity
  {    
    /// <summary>
    /// Evento disparado ao acessar a tela inicial da aplicação.
    /// </summary>
    /// <param name="bundle">Container de componentes.</param>
    protected override void OnCreate(Bundle bundle)
    {
      RequestedOrientation = ScreenOrientation.Portrait;
      base.OnCreate(bundle);
      StartThread();
    }

    /// <summary>
    /// Thread para força que a tela inicial seja exibida por pelo menos 2 segundos.
    /// </summary>
    private void StartThread()
    {
      MobileDatabaseSigleton.MobileDatabase.CriarTabelaConfiguracoes();
      new Thread(new Runnable(
        delegate
        {
          Thread.Sleep(2000);
          var activityMain = new Intent(this, typeof(ActivityFormMain));
          Finish();
          StartActivity(activityMain);         
        }
        )).Start();
    }
  }
}

